﻿using System;
using System.Data.SqlClient;
using System.Data;

namespace ExoticCarRental
{
    public class DataLayer
    {
        private SqlConnection conn;
        public DataLayer()
        {
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = "Data Source=ss.cs.luc.edu;Initial Catalog=ExoticCarRental;User Id=mjohnson4;Password=p29476;";
                conn.Open();
            }
            catch (Exception e)
            {
                throw e;
            }
            
        }

        public DataTable ExecuteSelect(string sql)
        {
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            conn.Close();
            return dt;

        }


        public DataTable Execute(SqlCommand cmd)
        {
            cmd.Connection = conn;
            SqlDataReader rd = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(rd);
            conn.Close();
            return dt;

        }



        public int ExecuteProcNonQuery(SqlCommand cmd)
        {
            cmd.Connection = conn;
            
            int rowsaffected = cmd.ExecuteNonQuery();
            conn.Close();
            return rowsaffected;

        }

  

    }
}
